const eris = require("eris");
const fs = require("fs");

const config = require("./config.json");
const commDir = "./commands/" // Commands directory.
const client = new eris(config.token, { intents: ["guilds", "guildMembers", "guildMessages"] }); // Be sure to place the token in the config.json file.

client.on("messageCreate", message => {

    if(!message.content.startsWith(config.prefix)) return; // Ignore any messages that do not start with the bot's prefix.
    if(message.member.id != config.authorisedUser) return; // Ignore any messages by anyone other than the authorised user.

    const args = message.content.split(" ");
    const comm = args.shift().slice((config.prefix).length);

    try{
        const commFile = require(commDir + comm);

        commFile.run(client, message, args);
    }
    catch(e){
        console.error(e.stack);
    }

});

try{
    client.connect();
    console.log("Connected.");
}
catch(e){
    console.error(e.stack + "\a\n=====\nFailed to login. Terminating.");
    process.exit(0);
}
